import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  // 用户token
  const token = ref<string>(localStorage.getItem('token') || '')
  
  // 设置token
  const setToken = (newToken: string) => {
    token.value = newToken
    localStorage.setItem('token', newToken)
  }
  
  // 清除token
  const clearToken = () => {
    token.value = ''
    localStorage.removeItem('token')
  }
  
  // 判断是否已登录
  const isLoggedIn = () => {
    return !!token.value
  }
  
  return {
    token,
    setToken,
    clearToken,
    isLoggedIn
  }
}) 